package neca.tmazo.persistencia;

import neca.tmazo.datasets.*; 

public interface PersistencyFacade {
	
	/**
	 * Returns the album specified by the method parameters.
	 * @param title the album title
	 * @param author the album author
	 * @return an Album object that represents the searched album
	 * @throws BBDDException if there is a problem with database
	 */
	public Album getAlbum(String title, String author) throws BBDDException;
	
	/**
	 * Returns the song specified by the method parameters.
	 * @param title the song title
	 * @param author the song author
	 * @return a Song object that represents the searched album
	 * @throws BBDDException if there is a problem with database
	 */
	public Song getSong(String title, String author) throws BBDDException;
	
	
	/**
	 * Returns all the songs whose title is the specified by the method parameter.
	 * @param title the songs title to search
	 * @return the songs whose title matches with the specified
	 * @throws BBDDException if there is a problem with database
	 */
	public Song[] getSongsByTitle(String title) throws BBDDException;
	
	
	/**
	 * Returns all the songs whose author is the specified by the method parameter.
	 * @param author the songs author to search
	 * @return the songs whose title matches with the specified
	 * @throws BBDDException if there is a problem with database
	 */
	public Song[] getSongsByAuthor(String author) throws BBDDException;


	/**
	 * Returns all the songs whose release year is the specified by the method parameter.
	 * @param year the songs release year to search
	 * @return the songs whose release year matches with the specified
	 * @throws BBDDException if there is a problem with database
	 */
	public Song[] getSongsByYear(int year) throws BBDDException;

	/**
	 * Returns all the songs whose gender is the specified by the method parameter.
	 * @param gender the songs gender to search
	 * @return the songs whose gender matches with the specified
	 * @throws BBDDException if there is a problem with database
	 */
	public Song[] getSongsByGender(String gender) throws BBDDException;
	
	/**
	 * Returns all the songs whose price is lower or equal than the specified by the method parameter.
	 * @param price the songs maximum price to search
	 * @return the songs whose price is lower or equal than the specified
	 * @throws BBDDException if there is a problem with database
	 */
	public Song[] getSongsByPrice(double price) throws BBDDException;

	/**
	 * Returns all the songs contained on the album represented by the method parameter.
	 * @param album the album of the songs that will be returned
	 * @return the songs contained on the album represented by the method parameter.
	 * @throws BBDDException if there is a problem with database
	 */
	public Song[] getSongsByAlbum(Album album) throws BBDDException;

	/**
	 * Returns all the albums whose title is the specified by the method parameter.
	 * @param title the albums title to search
	 * @return the albums whose title matches with the specified
	 * @throws BBDDException if there is a problem with database
	 */
	public Album[] getAlbumsByTitle(String title) throws BBDDException;
	
	/**
	 * Returns all the albums whose author is the specified by the method parameter.
	 * @param author the albums author to search
	 * @return the albums whose author matches with the specified
	 * @throws BBDDException if there is a problem with database
	 */
	public Album[] getAlbumsByAuthor(String author) throws BBDDException;
	
	/**
	 * Returns all the albums whose release year is the specified by the method parameter.
	 * @param year the albums release year to search
	 * @return the albums whose release year matches with the specified
	 * @throws BBDDException if there is a problem with database
	 */
	public Album[] getAlbumsByYear(int year) throws BBDDException;
	
	/**
	 * Returns all the albums whose gender is the specified by the method parameter.
	 * @param gender the albums gender to search
	 * @return the albums whose gender matches with the specified
	 * @throws BBDDException if there is a problem with database
	 */
	public Album[] getAlbumsByGender(String gender) throws BBDDException;
	
	/**
	 * Returns all the albums whose price is lower or equal than the specified by the method parameter.
	 * @param price the albums maximum price to search
	 * @return the albums whose price is lower or equal than the specified
	 * @throws BBDDException if there is a problem with database
	 */
	public Album[] getAlbumsByPrice(double price) throws BBDDException;

	/**
	 * Gets all the music pieces of a specific author
	 * 
	 * @param author the music author
	 * @return all the music pieces of the specified author
	 * @throws BBDDException if there is a problem with database
	 */
	public Music[] getMusicByAuthor(String author) throws BBDDException;
	
	/**
	 * Inserts a new song into the database. NOTE: this method doesn't insert the song's votes.
	 * @param song the song to be inserted
	 * @throws BBDDException if there is a problem with database
	 * @return false when the song already exists
	 */
	public boolean insert(Song song) throws BBDDException;
	
	/**
	 * Inserts a new album into the database. NOTE: this method doesn't insert the album's votes.
	 * @param album the album to be inserted
	 * @throws BBDDException if there is a problem with database
	 * @return false when the album already exists
	 */
	public boolean insert(Album album) throws BBDDException;

	/**
	 * Inserts into the database a new user with artist privileges.
	 * @param user the user to insert into the database, as an ArtistUser class instance
	 * @throws BBDDException if there is a problem with database
	 * @return false when the user already exists
	 */
	public boolean insert(ArtistUser user) throws BBDDException;
	
	/**
	 * Inserts into the database a new user with normal privileges.
	 * @param user the user to insert into the database, as an NormalUser class instance
	 * @throws BBDDException if there is a problem with database
	 * @return false when the user already exists
	 */
	public boolean insert(NormalUser user) throws BBDDException;
	
	/**
	 * Returns the user whose username is the specified by the method parameter.
	 * 
	 * @param username the username string of the user to match
	 * @return an instance of User that represents the user whose username is specified by the
	 * method parameter
	 * @throws BBDDException if there is a problem with database
	 */
	public User getUser(String username) throws BBDDException;
	
	/**
	 * Checks if an username exists into the database.
	 * 
	 * @param username the username to check
	 * @return [true] if the username exists. [false] otherwise.
	 * @throws BBDDException if there is a problem with database
	 */
	public boolean checkUser(String username) throws BBDDException;
	
	/**
	 * Updates the price of the musical piece specified by the method parameters.
	 * 
	 * @param title the piece title to update
	 * @param author the piece author to update
	 * @param newPrice the new piece price
	 * @throws BBDDException if there is a problem with database
	 */
	public void updatePiecePrice(String title, String author, double newPrice) throws BBDDException;
	
	/**
	 * Checks if there is a song in the database whose title and author are the specified by the method parameters.
	 * 
	 * @param title the song title
	 * @param author the song author
	 * @return [true] if there is a song with these title and author. [false] otherwise
	 * @throws BBDDException if there is a problem with database
	 */
	public boolean isSong(String title, String author) throws BBDDException;
	
	/**
	 * Checks if there is an album in the database whose title and author are the specified by the method parameters.
	 * 
	 * @param title the album title
	 * @param author the album author
	 * @return [true] if there is an album with these title and author. [false] otherwise
	 * @throws BBDDException if there is a problem with database
	 */
	public boolean isAlbum(String title, String author) throws BBDDException;
	
	
	/**
	 * Associates multiple songs to an Album.
	 * 
	 * @param s existing songs to associate
	 * @param a an existing album to associate
	 * @throws BBDDException if there is a problem with database
	 */
	public void associateSongsAlbums(Song[] s, Album a) throws BBDDException;
	
	/**
	 * Gets all the musical pieces that their fields fetch with the method
	 * parameters.
	 * 
	 * @param title the title of the musical piece
	 * @param author the author of the musical piece
	 * @param gender the gender of the musical piece
	 * @param year the year of the musical piece
	 * @param price the price of the musical piece
	 * @return all the musical pieces that their fields fetch with the method parameters
	 * @throws BBDDException if there is a problem with SQL database
	 */
	public Music[] query (String title, String author, String gender, int year, double price) throws BBDDException;

	/**
	 * Saves user purchase.
	 * 
	 * @param user the user that has purchased the music piece.
	 * @param music the purchased music piece
	 * @return [true] if there is no error. [false] otherwise.
	 * @throws BBDDException if there is a problem with database
	 */
	public boolean buySong(User user, Music music) throws BBDDException;

	/**
	 * Checks if a music piece has been purchased by an user.
	 * 
	 * @param user the buyer user
	 * @param music the purchases
	 * @return [true] if the music piece has been purchased by the user. [false] otherwise.
	 * @throws BBDDException if there is a problem with database
	 */
	public boolean isPurchased(User user, Music music) throws BBDDException;

	/**
	 * Saves the user vote.
	 * 
	 * @param user the user that has voted
	 * @param music the voted music piece
	 * @param vote the value of user vote. [true] if user likes music piece, [false] otherwise.
	 * @return [true] if there is no error, [false] otherwise.
	 * @throws BBDDException if there is a problem with database
	 */
	public boolean vote(User user, Music music, boolean vote) throws BBDDException;

	/**
	 * Gets all music pieces purchased by an user.
	 * 
	 * @param user the buyer user
	 * @return the music pieces purchased by the user
	 * @throws BBDDException if there is a problem with database
	 */
	public Music[] purchased(User user) throws BBDDException;

	/**
	 * Gets the user vote for a song
	 * 
	 * @param user the user who has make the vote
	 * @param music the voted music piece
	 * @return 1 if user voted positive, -1 if user voted negative. 0 if the user didn't vote.
	 * @throws BBDDException if there is a problem with database
	 */
	public int vote(User user, Music music) throws BBDDException;

	/**
	 * Returns 50 pseudo-random albums and 50 pseudo-random songs from the database.
	 * @return 50 pseudo-random albums and 50 pseudo-random songs from the database
	 * @throws BBDDException if there is a problem with database
	 */
	public Music[] hoyRecomendamos() throws BBDDException;
}
